package com.dmz.workflow.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

/**
 * description:swagger配置类
 * 启动Ui可查看接口
 */
@Configuration
@ConditionalOnProperty(prefix = "swagger",value = {"enable"},havingValue = "true")
@EnableSwagger2
public class SwggerConfig {

    @Bean
    public Docket bmsApi() {
        return buildDocket("短信服务","com.ech.nms.service");
    }


    @Bean
    public Docket passToken() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName("普通请求")
                .select()
                .paths(PathSelectors.any())
                .build();
    }
    private Docket buildDocket(String name,String packageName) {
        List<Parameter> pars = new ArrayList<>();
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).groupName(name)
                .select()
                .apis(RequestHandlerSelectors.basePackage(packageName))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars);
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("华世界-服务接口")
                .version("v1")
                .build();
    }
}
